package top.sqdpt.web.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import top.sqdpt.file.entity.dto.FileUpload;
import top.sqdpt.file.service.FileService;
import top.sqdpt.rag.service.AiChatService;
import top.sqdpt.web.entity.Result;

import java.io.IOException;

@RestController
@RequestMapping("/rag")
public class RagController {

    @Autowired
    private AiChatService aiChatService;

    @Autowired
    private FileService fileService;

    @PostMapping("/load")
    public Result<String> load(@RequestParam("file") MultipartFile file) throws IOException {
        FileUpload fileUpload = new FileUpload();
        fileUpload.setInputStream(file.getInputStream());
        fileUpload.setFilename(file.getOriginalFilename());
        fileUpload.setFileSize(file.getSize());
        fileUpload.setFileType(file.getContentType());
        fileUpload.setCreateBy(0);
        String path = fileService.saveFile(fileUpload);
        return Result.success(path);
    }

    @PostMapping("/load")
    public Result<String> load(String text) {
        return Result.success(fileService.saveFile(text));
    }

}
